package cn.tedu.egarticle.base.filters;

import cn.tedu.egarticle.pojo.vo.UserVo;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebFilter(filterName = "loginCheckFilter",urlPatterns = "/v1/user/article")
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException, ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        HttpSession session = request.getSession();
        UserVo user = (UserVo) session.getAttribute("user");
        if (user == null) {
            filterChain.doFilter(request, response);
        }
        throw new RuntimeException("用户未登录0001");
    }
}
